package com.njit.WeStudy.control;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * @author yuruiqiao
 * @date 2020/1/26
 * @description 用于测试
 */
@Controller
public class testController {
    @RequestMapping(path = "/test")
    public  String test(){
        return "test";
    }

    public static void main(String[] args) {
        int[] array = {0,1,0,2,1,0,1,3,2,1,2,1};
        int sum = 0;
        int edge = 0;
        int maxIndex = 0;
        //有关柱子接水的算法题,目前所知最快时间复杂度是O(n)
        //找到最大值
        for (int i = 0; i <array.length; i++) {
            if(array[i]>=array[maxIndex]){
                maxIndex = i;
            }
        }
        //两边各进行计算(并在一起了)
        for (int i = 0; i <array.length; i++) {
            if((maxIndex-i)*array[i]>=(maxIndex-i)*edge){
                edge = array[i];
            }else{
                sum+= Math.abs(edge - array[i]);
            }
        }

        System.out.println(sum);
    }
}
